package com.passioneffect.widgets {
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;	

	/**
	 * @author Passion Effect
	 */
	public class Mask {
		private var compWidth : Number;
		private var compHeight : Number;
		private var align : String = "center";
		private var mask_mc : Sprite;
		private var target : DisplayObject;
		private var opened : Boolean;
		
		public function Mask(target : DisplayObject,w : Number,h : Number,align : String = "center") {
			this.compHeight = h;
			this.compWidth = w;
			this.align = align;
			this.target = target;
		}

		public function drawMask() : void {
			var g : Graphics = mask_mc.graphics;
			g.clear();
			g.lineStyle();
			g.beginFill(0x000000, 0);
			g.drawRect(0, 0, compWidth, compHeight);
			g.endFill();
		}

		public function open() : void {
			opened=true;
			mask_mc = new Sprite();
			mask_mc.x = target.width/2-compWidth/2;
			mask_mc.y = target.height/2-compHeight/2;
			drawMask();
			target.parent.addChild(mask_mc);	
			target.mask = mask_mc;
		}

		public function close() : void {
			if(opened) {
				opened = false;
				target.mask = null;
				mask_mc.parent.removeChild(mask_mc);
			}
		}
	}
}
